package com.markpim.algo;

public class Apl {

	private static final boolean SHOW_OUTPUT = false;
	public static final int ACCURACY = 10;

	public static void main(String[] args) {

		int start = 64000;
		int count = 1024000;

		for (int i = start; i <= count; i = i * 2)
			new InsertionSort(integerArray(i));

		for (int i = start; i <= count; i = i * 2)
			new MergeSort(integerArray(i));

		for (int i = start; i <= count; i = i * 2)
			new QuickSort(integerArray(i));

	}

	public static int[] swap(int[] array, int i1, int i2) {
		int temp = array[i1];
		array[i1] = array[i2];
		array[i2] = temp;
		return array;
	}

	public static boolean isSorted(int[] numbers) {
		for (int i = 0; i < numbers.length - 1; i++) {
			if (numbers[i] > numbers[i + 1])
				return false;
		}
		return true;
	}

	public static void printSortingStats(int[] numbers, String algorithm,
			long time) {
		boolean sorted = isSorted(numbers);

		System.out.printf(algorithm + (sorted ? " output: " : ":"));
		if (SHOW_OUTPUT)
			for (int i = 0; i < numbers.length; i++) {
				System.out.printf(numbers[i]
						+ (i == numbers.length - 1 ? "" : "-"));
			}
		System.out.println();
		System.out.println("Confirm sorted: " + sorted);
		if (sorted)
			System.out.println("Time: " + time);

		System.out.println();
	}

	private static int[] integerArray(int length) {
		int[] array = new int[length];
		for (int i = 0; i < length; i++) {
			array[i] = (int) (Math.random() * length * 10);
		}
		return array;
	}

}
